package nku.csc364;

/* Raj Akula
 *
 * InputValidator.java
 * 
 * validates data fields for person
 *
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class InputValidator {

	// Any alphabet upper or lower case.
	public static boolean isFnameValidated(String fname){
		boolean result=false;
		if (fname.matches("[A-Za-z]+")){
			result=true;
		}
		return result;
	}
	
	
	// Any alphabet upper or lower case.	
	public static boolean isLnameValidated(String lname){
		boolean result=false;
		if (lname.matches("[A-Za-z]+")){
			result=true;
		}
		return result;
	}
	
	// Exactly 9 digits
	public static boolean isSsnValidated(String ssn){
		boolean result=false;
		if (ssn.matches("[0-9]{9}")){
			result=true;
		}
		return result;
	}
	
	// Exactly 10 digits
	public static boolean isPhoneValidated(String phone){
		boolean result=false;
		if (phone.matches("[0-9]{10}")){
			result=true;
		}
		return result;
	}
	
	
	// Exactly one character M or F  upper or lower case.
	public static boolean isGenderValidated(String gender){
		boolean result=false;
		if (gender.matches("[mM,fF]{1}")){
			result=true;
		}
		return result;
	}
	
	// Maker sure i can parse the date into a date format to validate. 
	public static boolean isBirthDateValidated(String dob){
		boolean result = false;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("M/d/y");
		simpleDateFormat.setLenient(false);
		Date birthDate = null;
		try{
			birthDate = simpleDateFormat.parse(dob);
			result=true;
		}
		catch(ParseException pe){
		}
		return result;		
	}
}
